﻿/// <reference name="MicrosoftAjax.debug.js"/>
/// <reference path="OpenAjax/OpenAjax.js"/>

OpenAjax.hub.registerLibrary("MicrosoftAjax", "http://ajax.asp.net", "1.0");

Type.registerNamespace("Sys.OpenAjax");

Sys.OpenAjax._Helper = function() {
}
Sys.OpenAjax._Helper.prototype = {
    mapEventToMessage: function(owner, eventName, messageName, publisherDataMapper) {
        /// <summary>
        ///     Maps a Microsoft Ajax Library event to an OpenAjax hub message.
        ///     Every time the event is raised, a message will be sent to the hub.
        /// </summary>
        /// <param name="owner" type="Object">The object that fires the event.</param>
        /// <param name="eventName" type="String">The name of the event to map.</param>
        /// <param name="messageName" type="String">The name of the OpenAjax hub message to map to.</param>
        /// <param name="publisherDataMapper" type="Function" optional="true">
        ///     An optional function that maps the event arguments to the expected publisherData.
        ///     If not specified, no publisherData is sent.
        ///     The signature of this function is Object function(Object this, EventArgs args).
        /// </param>
        /// <returns type="Function">A map function pointer to use when unmapping the event.</returns>
        var handler = function(sender, args) {
            OpenAjax.hub.publish(messageName, publisherDataMapper ? publisherDataMapper(sender, args) : null);
        }
        owner["add_" + eventName](handler);
        return handler;
    },
    unmapEvent: function(owner, eventName, map) {
        owner["remove_" + eventName](map);
    }
}
Sys.OpenAjax._Helper.registerClass("Sys.OpenAjax._Helper");

Sys.OpenAjax.Helper = new Sys.OpenAjax._Helper();